<template>
  <el-dialog
    :title="title"
    v-model="visible"
    destroy-on-close
    @close="close"
    width="600px"
    custom-class='my-dialog'
  >
    <el-timeline class="content-box">
      <el-timeline-item
        v-for="(activity, index) in dataList"
        :key="index"
        :timestamp="activity.time"
        :class="index == 0 ? 'current' : ''"
         placement="top"
      >
        <div class="d-img-flex">
          <div class="img-box-2"  v-for="obj in activity.previewList" :key="obj">
            <previewImg :files="obj" type="epms"></previewImg>
            <p class="monomer">{{obj.monomerName}}</p>
          </div>
        </div>
      </el-timeline-item>
    </el-timeline>
  </el-dialog>
</template>
<script lang="ts" setup>
import { ref, defineEmits,watch } from "vue";
import NotifMessage from "/@/utils/message/notification";
import previewImg from "/@/components/previewImg/index.vue";
 import {
    getPicture
  } from "/@/api/board";
const props = defineProps({
  projectId: {
    type: Number || String,
    required: true
  },
  title:{
    title:String,
    default:""
  }
});
const emit = defineEmits(["closeDetail"]);
const dataList = ref([]);
const visible = true
//获取项目数据
const getTableData = async (projectId) => {
  try {
    const { code, data, message } = await getPicture(projectId);
    if (code === 200) {
      const activities = data;
      let list = [];
      activities.forEach(item => {
        const keyList = Object.keys(item);
        keyList.map(ele => {
          list.push({
            time:ele,
            imgList:item[ele]
          })
        })
      });

      list.forEach(obj => {
        obj?.imgList.map(ele => {
          ele.dayAttachList = JSON.parse(ele?.dayAttachment);
          ele.dayAttachList.forEach(tar => {
            tar.monomerName = ele.monomerName
          })
        });
        obj.previewList = obj?.imgList.flatMap(item => item.dayAttachList)
      })
      dataList.value = list;
    }
    else {
      NotifMessage.error(message || "获取数据异常");
    }
  } catch (err) {
    console.log(err);
  }
}

const close = () =>{
  emit("closeDetail")
}
watch(() => props.projectId,(newValue)=>{
  if(newValue){
    getTableData(newValue)
  }
},
{
  deep: true,
  immediate: true
})
</script>
<style lang="scss" scoped>

.my-dialog{
  :global(.el-dialog){
    border-radius: 8px;
  }
  .content-box {
    height: 500px;
    padding-top:16px;
    overflow: auto;
    .current{
      :deep .el-timeline-item__timestamp{
        color:#0073E5
      }
      :deep .el-timeline-item__node{
        background-color:#0073E5;
      }
    }
    .d-img-flex {
      display: flex;
      flex-wrap: wrap;
    }
    .img-box-2 {
      position: relative;
      width: 112px;
      height: 90px;
      border-radius: 6px;
      text-align: center;
      overflow: hidden;
      margin-right: 12px;
      img {
        max-width: 100%;
      }
      .monomer{
        position: absolute;
        font-size: 12px;
        font-weight: 500;
        line-height: 20px;
        color: #FFFFFF;
        left: 6px;
        bottom: 6px;
      }
    }

    .el-timeline-item{
      padding-bottom: 16px;
      margin: 0 20px;
    }
    :deep .el-timeline-item__timestamp{
      font-size: 16px;
      line-height: 24px;
      color: #333333;
      padding-top: 0;
    }

    :deep .el-timeline-item__tail {
      top: 8px;
    }
  }

  :global(.el-dialog .el-dialog__header) {
    border-bottom: 1px solid #E4E7ED;
    background-color: #fff;
    border-radius: 8px 8px 0 0;
  }
}


</style>
